<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Models\cms\Menu;
use App\Models\cms\Role;
use App\Models\cms\User;
use App\Models\cms\Permission;
use App\Models\cms\RoleUser;
use App\Models\cms\PermissionRole;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();
        $this->call(UserTableSeeder::class);
        $this->call(MenuTableSeeder::class);
        $this->call(RoleTableSeeder::class);
        $this->call(PermissionTableSeeder::class);
        $this->call(RoleUserTableSeeder::class);
        $this->call(PermissionRoleTableSeeder::class);
        $this->call(CorporationsTableSeeder::class);
        $this->call(OrganizationsTableSeeder::class);
        $this->call(AppUsersTableSeeder::class);
        $this->call(ClassifyTableSeeder::class);
        $this->call(StaffStyleTableSeeder::class);
        $this->call(NewsTableSeeder::class);
        Model::reguard();
    }
}

class UserTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("users")->delete();

        User::create(["name" => "admin", "email" => "admin@admin.com", "password" => bcrypt(123456)]);
    }
}

class MenuTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("menus")->delete();

        Menu::create(["parent_id" => "0", "name" => "首页管理", "url" => "index", "description" => "展示系统的各项基础数据"]); //id：1

//        Menu::create(["parent_id" => "0", "name" => "xx", "url" => "xx.index", "description" => ""]);
//        Menu::create(["parent_id" => "0", "name" => "新增xx", "url" => "xx.create", "description" => "", "is_hide" => 1]);
//        Menu::create(["parent_id" => "0", "name" => "编辑xx", "url" => "xx.edit", "description" => "", "is_hide" => 1]);

    }
}

class RoleTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("roles")->delete();

        Role::create(["name" => "admin", "display_name" => "User Administrator", "description" => "User is allowed to manage and edit other users"]);
        Role::create(["name" => "owner", "display_name" => "Project Owner", "description" => "User is the owner of a given project"]);
    }
}

class PermissionTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("permissions")->delete();

        Permission::create(["display_name" => "首页管理", "name" => "index"]); // id:1

//        Permission::create(["display_name" => "xx", "name" => "xx.index"]); // id:2
//        Permission::create(["display_name" => "新增xx", "name" => "xx.create"]);
//        Permission::create(["display_name" => "保存xx", "name" => "xx.store"]);
//        Permission::create(["display_name" => "编辑xx", "name" => "xx.edit"]);
//        Permission::create(["display_name" => "更新xx", "name" => "xx.update"]);
    }
}

class RoleUserTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("role_user")->delete();

        RoleUser::create(["user_id" => 1, "role_id" => 1]);
    }
}

class PermissionRoleTableSeeder extends Seeder
{
    public function run()
    {
        DB::table("permission_role")->delete();

        /**
         * 权限role
         */
        for ($role = 1; $role <= 2; $role++) {
            for ($permission = 1; $permission <= 1; $permission++) {
//            for ($permission = 1; $permission <= 6; $permission++) {
                PermissionRole::create(["permission_id" => $permission, "role_id" => $role]);
            }
        }
    }
}

class CorporationsTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_corporations")->delete();

		\App\Models\api\Corporations::create(["name" => "企课网", "ceo" => "张凌", "address" => "北京朝阳",
			"logo" => "http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=ae4e87268d94a4c21e2eef68669d71a0/7c1ed21b0ef41bd5d5a88edd5bda81cb39db3d1b.jpg",
			"contact" => "1501234567"
		]);
	}
}


class OrganizationsTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_organizations")->delete();

		\App\Models\api\Organizations::create(["corporation_id" => 1, "name" => "总裁办", "number" => 0]);
	}
}


class AppUsersTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_users")->delete();

		\App\Models\Api\User::create(["nickname" => "张三", "phone" => "1891234567", "password" => bcrypt(123456),
			'birthday' => '1995.05.05',
			'corporation_id' => 1,
			'organization_id' => 1,
			'position' => 'php开发',
		]);
	}
}


class ClassifyTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_classify")->delete();

		\App\Models\api\Classify::create(["name" => "营销"]);
	}
}

class StaffStyleTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_staff_style")->delete();

		\App\Models\api\StaffStyle::create(['corporation_id' => 1,
			"img" => "http://suo.im/2maWx9",
			"title" => "我是员工风采","content" => "<h3>我是员工风采内容，我是自带H5标签的。<h3>"
		]);
	}
}

class NewsTableSeeder extends Seeder
{
	public function run()
	{
		DB::table("app_news")->delete();

		\App\Models\api\News::create(['corporation_id' => 1,
			"img" => "http://suo.im/2maWx9",
			"title" => "我是企业新闻","content" => "<h3>我是企业新闻内容，我是自带H5标签的。<h3>"
		]);
	}
}